import Vue from 'vue'
import App from './App.vue'
import store from './store/index'
// 导入 Element_ui
import ElementUI from 'element-ui'
// 导入 Element-ui 样式
import 'element-ui/lib/theme-chalk/index.css'
// 插件 Element-ui
Vue.use(ElementUI)

// 导入全局初始化样式
import './assets/index.css'

// 路由整合
import VueRouter from 'vue-router'
Vue.use(VueRouter)


// 路由懒加载
const discovery = () => import('./views/01.discovery.vue')
const playlists = () => import('./views/02.playlists.vue')
const songs = () => import('./views/03.songs.vue')
const mvs = () => import('./views/04.mvs.vue')
const result = () => import('./views/05.result.vue')
const playlist = () => import('./views/06.playlist.vue')
const mv=()=>import('./views/07.mv.vue')

const router = new VueRouter({
  routes: [
    {
      path: '/',
      redirect: '/discovery'
    },
    {
      // 发现音乐
      path: '/discovery',
      component: discovery,
      meta: {
        title:'发现'
      }
    },
    {
      // 推荐歌单
      path: '/playlists',
      component: playlists,
      meta: {
        title:'歌单'
      }
    },
    {
      // 推荐歌单
      path: '/playlist',
      component: playlist,
      meta: {
        title:'列表'
      }
    },
    {
      // 最新音乐
      path: '/songs',
      component: songs,
      meta: {
        title:'音乐'
      }
    },
    {
      // 最新音乐
      path: '/mvs',
      component: mvs,
      meta: {
        title:'mv'
      }
    },
    // mv详情
    {
      path: '/mv',
      component: mv,
      meta: {
        title:'mv详情'
      }
    },
    // 搜索结果页
    {
      path: '/result',
      component: result,
      meta: {
        title:'搜索结果'
      }
    }
  ]
})

// 解决两次访问相同路由地址报错
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

// 路由导航守卫
router.beforeEach((to, from, next) => {
  document.title = to.matched[0].meta.title
  console.log(to)
  next()
})

Vue.config.productionTip = false


new Vue({
  render: h => h(App),
  // 挂载到Vue示例上
  router,
  store
}).$mount('#app')
